package start.demo01.erupt;

import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Data
public class Body {

    private List<String> list= new ArrayList();
    {
        list.add("1111");
        list.add("2222");
        list.add("43445");
        list.add("4535t3");
    }

    private void update(){
        list=new ArrayList();
    }

    public void read(){
        List<String> list2=list;
        for(int i=0;i<list2.size();i++){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(list2.get(i));
        }
    }

    public static void main(String[] args){
        Body body=new Body();
        new Thread(()->body.read()).start();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        new Thread(()->body.update()).start();

    }
}
